#ifndef _TIMER_H
#define _TIMER_H

#include <ogre\Ogre.h>

#include "ODN_Maths.h"

namespace ouden {

class CGameTimer;

//Game timer receiver interface
class IGameTimerListener
{
public:
	//TODO: Check if these need game timer passed to them
	virtual bool onTick(CGameTimer* pTimer) = 0;
	virtual bool onFrameStart(CGameTimer* pTimer) = 0;	
};

//Game timer object calls functions in listener interface
class CGameTimer
{

public:
	
	//Constructor and destructor 
	CGameTimer();
	~CGameTimer()		{}

    //Variable access functions 
    int 	getFPS()				{ return m_iFPS; }
    float 	getElapsed()			{ return m_iElapsed; }
    float 	getElapsedSqrd()		{ return m_iElapsed2; }
    long 	getTime()				{ return m_iCurTime; }
	
	void 	setElapsed(long iElapsed)		{ m_iElapsed = iElapsed; m_iElapsed2 = iElapsed * iElapsed; }
	
	//Updates the timer and calls the onTick and frameStarted events in the listener
    bool 	update(IGameTimerListener* pListener);
    
private:
	
	long 	m_iTimePerTick; 	//The fixed tick rate for game logic
	Scalar 	m_fTickExcess;		//The left over time from the last tick
	
	long 	m_iFPS;				//FPS of the engine
    long 	m_iElapsed;			//Time elapsed since last frame
    long 	m_iElapsed2;		//Elapsed squared
    long 	m_iCurTime;			//Current time
    
    long 	m_iFPSCounter;		//Holds the current FPS count
    long 	m_iLastFrameTime;	//Holds the time of the last FPS update
    
	Ogre::Timer* m_pOgreTimer;

};

} //namespace ouden

#endif //_TIMER_H 
